//
//  MainTabController.m
//  Hai
//
//  Created by 千金贷 on 16/2/23.
//  Copyright © 2016年 wangzijian. All rights reserved.
//

#import "MainTabController.h"
#import "MyViewController.h"
#import "BYHomeViewController.h"
#import "BMHomeViewController.h"
#import "MainNavigationController.h"
#import "SVHomeViewController.h"
#import "GreetController.h"
#import "YMHomeViewController.h"
#import "GreetController.h"
#import "BYRecordController.h"
#import "PublishViewController.h"
#import "ThemeViewController.h"
#import "SNCalendarViewController.h"
#import "YMCalendarViewController.h"
#import "BYCalendarViewController.h"
#import "BMCalendarViewController.h"
@interface MainTabController ()<UITabBarControllerDelegate>

@end

@implementation MainTabController

- (id)init
{
    self = [super init];
    if (self) {
        
        
        //self.tabBar.backgroundColor = BlackColor;
       // self.tabBar.barTintColor = BlackColor;
        
        self.delegate = self;
        // 创建子控制器
        [self _createViewCtrollers];
        
    }
    return self;
}

- (void)_createViewCtrollers
{
    
    
    for (UIView *view in self.view.window.subviews) {
        if (view.tag == 404) {
            [view removeFromSuperview];
        }
    }
    // 创建三级控制器
     BYHomeViewController *homeVC = [[BYHomeViewController alloc] init];
     BMCalendarViewController *investVC2 = [[BMCalendarViewController alloc] init];
     GreetController *investVC3 = [[GreetController alloc] init];
     ThemeViewController*investVC4 = [[ThemeViewController alloc] init];
     MyViewController *investVC5 = [[MyViewController alloc] init];
    
    
    // 按钮未选中状态图
    NSArray *unselectImgsNames   = @[@"shouye",
                                     @"rili",
                                     @"tixing",
                                     @"huati",
                                     @"wode"];
    // 按钮选中状态图
    NSArray *selectedImgsNames = @[@"shouye2",
                                   @"rili2",
                                   @"tixing2",
                                   @"huati2",
                                   @"wode2"];
    
    //按钮名字
    NSArray *buttonNames = @[@"首页",@"日历",@"提醒",@"话题",@"我的"];
    
    // 创建二级控制器（导航控制器）
    NSArray *viewcontrollers = @[homeVC,investVC2,investVC3,investVC4,investVC5];
    NSMutableArray *viewContrls = [NSMutableArray arrayWithCapacity:5];
    for (int i = 0; i < viewcontrollers.count; i++) {
        MainNavigationController *navigation = [[MainNavigationController alloc] initWithRootViewController:viewcontrollers[i]];
        navigation.tabBarItem.title = buttonNames[i];
        navigation.tabBarItem.selectedImage = [UIImage imageNamed:selectedImgsNames[i]];
        navigation.tabBarItem.image = [UIImage imageNamed:unselectImgsNames[i]];
        // 将导航控制器作为当前控制器的子控制器
        [viewContrls addObject:navigation];
        
    }
    
    // 将二级控制器的视图，添加到一级控制器的视图上显示
    self.viewControllers = viewContrls;
    
    self.selectedIndex = 0;
    
    self.tabBar.tintColor = TabColor;
    
    
    
}


#pragma mark - 按钮的点击事件
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
{
    
    
    //    for (int i = 0; i < self.viewControllers.count; i ++) {
    //        if ([viewController isEqual:self.viewControllers[i]] && i > 1 && !Getmemberid) {
    //            [[[UIAlertView alloc] initWithTitle:@"请注意"
    //                                        message:@"您需要先登录才能查看相关信息"
    //                                       delegate:self
    //                              cancelButtonTitle:@"留在当前页"
    //                              otherButtonTitles:@"登录", nil] show];
    //            return NO;
    //
    //        }
    //    }
    
    return YES;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
